package com.javabasic.algorithm.leetcode;

/**
 * @author xiongmin
 * @version 0.0.1
 * @description Created by work on 2021/10/9 9:12 下午
 * @see
 */
public class SlowestKey {

    /**
     * 逻辑思维题
     * @param releaseTimes
     * @param keysPressed
     * @return
     */
    public char slowestKey(int[] releaseTimes, String keysPressed) {
        int len = keysPressed.length();
        int maxPressTime = releaseTimes[0];
        char maxPressTimeChar = keysPressed.charAt(0);
        for (int i = 1; i < len; i++) {
            if (releaseTimes[i] - releaseTimes[i-1] > maxPressTime) {
                maxPressTime = releaseTimes[i] - releaseTimes[i-1];
                maxPressTimeChar = keysPressed.charAt(i);
            } else if (releaseTimes[i] - releaseTimes[i-1] == maxPressTime && keysPressed.charAt(i) > maxPressTimeChar) {
                maxPressTimeChar = keysPressed.charAt(i);
            }
        }
        return maxPressTimeChar;
    }
}
